﻿using FluentValidation;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;

namespace NetCoreProject.Api.Infrastructure.Validator
{
    public class GetBookInfoModel : IValidatableObject
    {
        public string UserRFID { get; set; }
        public string ItemRFID { get; set; }
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            GetBookInfoModelValidator validator = new GetBookInfoModelValidator();
            var result =validator.Validate(this);
            return result.Errors.Select(u => new ValidationResult(u.ErrorMessage, new[] { u.PropertyName }));
        }
    }
    public class GetBookInfoModelValidator : AbstractValidator<GetBookInfoModel>
    {
        public GetBookInfoModelValidator()
        {
            RuleFor(x => x.UserRFID).NotNull().NotEmpty(); 
            RuleFor(x => x.ItemRFID).NotNull().NotEmpty();
        }
    }
}
